package model

// 用户表结构体
type User struct {
	*Model
	Username string `json:"username" xorm:"VARCHAR(100) notnull default('') comment('用户名')"`
	Password string `json:"password" xorm:"VARCHAR(100) notnull default('') comment('密码')"`
	Mobile   string `json:"mobile" xorm:"VARCHAR(15) notnull default('') comment('手机号码')"`
	Email    string `json:"email" xorm:"VARCHAR(50) notnull default('') comment('邮箱')"`
	Status   int    `json:"status" xorm:"TINYINT(2) notnull default('0') comment('用户状态\n1:正常\n0:禁用\n-1:删除\n-2:锁定')"`
}

type LoginSwagger struct {
	Token string
}

// 验证手机号码
func (u User) CheckMobile(d *xorm.EngineGroup) (PUsers, error) {
	var pusers PUsers
	encryPhoneB, _ := openssl.AesECBEncrypt([]byte(pu.Phone), []byte(util.AddTo16(global.AppSetting.CryptKey)), openssl.ZEROS_PADDING)
	phone := util.EncodeBase64(string(encryPhoneB))
	_, err := d.Where("phone = ?", phone).Cols("id, is_deleted").Get(&pusers)

	if err != nil {
		return pusers, err
	}

	return pusers, nil
}
